package com.sub.project.mall.contorller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;


import com.sub.common.utils.StringUtils;
import com.sub.common.utils.poi.ExcelUtil;
import com.sub.framework.aspectj.lang.annotation.Log;
import com.sub.framework.aspectj.lang.enums.BusinessType;
import com.sub.framework.web.controller.BaseController;
import com.sub.framework.web.domain.AjaxResult;
import com.sub.framework.web.page.TableDataInfo;
import com.sub.project.mall.domain.PmsBrand;
import com.sub.project.mall.service.IPmsBrandService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【商品品牌】Controller
 *
 * @author ruoyi
 * @date 2020-08-03
 */
@RestController
@RequestMapping("/mall/brand")
public class PmsBrandController extends BaseController {
    @Autowired
    private IPmsBrandService pmsBrandService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsBrand pmsBrand) {
        startPage();
        QueryWrapper<PmsBrand> queryWrapper = new QueryWrapper<PmsBrand>();
        if (StringUtils.isNotBlank(pmsBrand.getName())) {
            queryWrapper.like("name", pmsBrand.getName());
        }
        if (StringUtils.isNotBlank(pmsBrand.getFirstLetter())) {
            queryWrapper.eq("first_letter", pmsBrand.getFirstLetter());
        }
        if (pmsBrand.getSort() != null) {
            queryWrapper.eq("sort", pmsBrand.getSort());
        }
        if (pmsBrand.getFactoryStatus() != null) {
            queryWrapper.eq("factory_status", pmsBrand.getFactoryStatus());
        }
        if (pmsBrand.getShowStatus() != null) {
            queryWrapper.eq("show_status", pmsBrand.getShowStatus());
        }
        if (pmsBrand.getProductCount() != null) {
            queryWrapper.eq("product_count", pmsBrand.getProductCount());
        }
        if (pmsBrand.getProductCommentCount() != null) {
            queryWrapper.eq("product_comment_count", pmsBrand.getProductCommentCount());
        }
        if (StringUtils.isNotBlank(pmsBrand.getLogo())) {
            queryWrapper.eq("logo", pmsBrand.getLogo());
        }
        if (StringUtils.isNotBlank(pmsBrand.getBigPic())) {
            queryWrapper.eq("big_pic", pmsBrand.getBigPic());
        }
        if (StringUtils.isNotBlank(pmsBrand.getBrandStory())) {
            queryWrapper.eq("brand_story", pmsBrand.getBrandStory());
        }
        List<PmsBrand> list = pmsBrandService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PmsBrand pmsBrand) {
        QueryWrapper<PmsBrand> queryWrapper = new QueryWrapper<PmsBrand>(pmsBrand);
        List<PmsBrand> list = pmsBrandService.list(queryWrapper);
        ExcelUtil<PmsBrand> util = new ExcelUtil<PmsBrand>(PmsBrand.class);
        return util.exportExcel(list, "brand");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pmsBrandService.getById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsBrand pmsBrand) {
        return toAjax(pmsBrandService.save(pmsBrand) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsBrand pmsBrand) {
        return toAjax(pmsBrandService.updateById(pmsBrand) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:brand:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsBrandService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
